<?php 
session_cache_expire(999999999);
if(!isset($_SESSION)) 
{ 
	session_start(); 
}
$lang = $_SESSION['lang'];
if (empty($lang) || $lang == "EN") {
	include "../../value/value_en.php";
} else if($lang == "VN") {
	include "../../value/value_vn.php";
}
else {
	include "../../value/value_kr.php";
}
include '../../operations/connection.php';	
include '../../content-accountant/invoicetax.php';



$idInvoices=$_REQUEST['str'];
$parts = explode('_', $idInvoices);
//
$sql="DELETE FROM `or_order_tax` WHERE ";
for ($i=1;$i<count($parts);$i++)
	$sql.=" (`orderid`='".$parts[$i]."') OR";
$sql.=" (`orderid`='0')";
mysql_query($sql);


if(isset($_REQUEST['loaitimkiem'])){
	$sql=$_SESSION['sqlinvoice1'];
	if($_REQUEST['loaitimkiem']=="ngay"){
		
		$sqlinvoice=mysql_query($sql);
		$dem=0;
		if(mysql_num_rows($sqlinvoice)>0){
			while($rin=mysql_fetch_array($sqlinvoice)){
				$dem++;
				$ob=new invoicetax();
				if($_REQUEST['not']!='none'){
					if($_REQUEST['not']=='false'){
						if($rin[$time]=='0000-00-00' || $rin[$time]=='')
							$ktdate=0;
						else
							$ktdate=getdate(strtotime($rin[$time]));
						
						$ob->Instance($rin['orderid'],$rin['order_time'],$ktdate['mon'],$ktdate['day'],$ktdate['year'],$rin['order_cus'],$rin['order_content'],$rin['order_quantity'],$rin['order_supply_rice'],$rin['order_tax'],$rin['order_total'],$rin['order_time_transaction'],$rin['is_status'],$rin['user_create'],$rin['date_create'],$rin['order_memo'],$rin['status'] );
						$ob->setCusname($rin['order_cusname']);
						if(array_key_exists ($rin[$time], $arr)==true){
							array_push ($arr[$rin[$time]],$ob);
						}else{
							$arr[$rin[$time]]=array();
							$arr[$rin[$time]][]=$ob;
						}
					}
					if($_REQUEST['not']=='true'){
						if($rin['order_time_transaction']=='0000-00-00' || $rin['order_time_transaction']==''){
							if($rin[$time]=='0000-00-00' || $rin[$time]=='')
								$ktdate=0;
							else
								$ktdate=getdate(strtotime($rin[$time]));
							
							$ob->Instance($rin['orderid'],$rin['order_time'],$ktdate['mon'],$ktdate['day'],$ktdate['year'],$rin['order_cus'],$rin['order_content'],$rin['order_quantity'],$rin['order_supply_rice'],$rin['order_tax'],$rin['order_total'],$rin['order_time_transaction'],$rin['is_status'],$rin['user_create'],$rin['date_create'],$rin['order_memo'],$rin['status'] );
							$ob->setCusname($rin['order_cusname']);
							if(array_key_exists ($rin[$time], $arr)==true){
								array_push ($arr[$rin[$time]],$ob);
							}else{
								$arr[$rin[$time]]=array();
								$arr[$rin[$time]][]=$ob;
							}
						}
					}
				}else{
					if($rin[$time]=='0000-00-00' || $rin[$time]=='')
						$ktdate=0;
					else
						$ktdate=getdate(strtotime($rin[$time]));
					
					$ob->Instance($rin['orderid'],$rin['order_time'],$ktdate['mon'],$ktdate['day'],$ktdate['year'],$rin['order_cus'],$rin['order_content'],$rin['order_quantity'],$rin['order_supply_rice'],$rin['order_tax'],$rin['order_total'],$rin['order_time_transaction'],$rin['is_status'],$rin['user_create'],$rin['date_create'],$rin['order_memo'],$rin['status'] );
					$ob->setCusname($rin['order_cusname']);
					if(array_key_exists ($rin[$time], $arr)==true){
						array_push ($arr[$rin[$time]],$ob);
					}else{
						$arr[$rin[$time]]=array();
						$arr[$rin[$time]][]=$ob;
					}
				}
			}
			$_SESSION['manginvoicetax']=$arr;
		}
	}
	if($_REQUEST['loaitimkiem']=="qui"){
		
		
		$sqlinvoice=mysql_query($sql);
		$dem=0;
		if(mysql_num_rows($sqlinvoice)>0){
			while($rin=mysql_fetch_array($sqlinvoice)){
				$dem++;
				$ob=new invoicetax();
				if($_REQUEST['not']!='none'){
					if($_REQUEST['not']=='false'){
						if($rin[$time]=='0000-00-00' || $rin[$time]=='')
							$ktdate=0;
						else
							$ktdate=getdate(strtotime($rin[$time]));
						
						$ob->Instance($rin['orderid'],$rin['order_time'],$ktdate['mon'],$ktdate['day'],$ktdate['year'],$rin['order_cus'],$rin['order_content'],$rin['order_quantity'],$rin['order_supply_rice'],$rin['order_tax'],$rin['order_total'],$rin['order_time_transaction'],$rin['is_status'],$rin['user_create'],$rin['date_create'],$rin['order_memo'],$rin['status'] );
						$ob->setCusname($rin['order_cusname']);
						if(array_key_exists ($ktdate['year'].'-'.$ktdate['mon'], $arr)==true){
							array_push ($arr[$ktdate['year'].'-'.$ktdate['mon']],$ob);
						}else{
							$arr[$ktdate['year'].'-'.$ktdate['mon']]=array();
							$arr[$ktdate['year'].'-'.$ktdate['mon']][]=$ob;
						}
					}
					if($_REQUEST['not']=='true'){
						if($rin['order_time_transaction']=='0000-00-00' || $rin['order_time_transaction']==''){
							if($rin[$time]=='0000-00-00' || $rin[$time]=='')
								$ktdate=0;
							else
								$ktdate=getdate(strtotime($rin[$time]));
							
							$ob->Instance($rin['orderid'],$rin['order_time'],$ktdate['mon'],$ktdate['day'],$ktdate['year'],$rin['order_cus'],$rin['order_content'],$rin['order_quantity'],$rin['order_supply_rice'],$rin['order_tax'],$rin['order_total'],$rin['order_time_transaction'],$rin['is_status'],$rin['user_create'],$rin['date_create'],$rin['order_memo'],$rin['status'] );
							$ob->setCusname($rin['order_cusname']);
							if(array_key_exists ($ktdate['year'].'-'.$ktdate['mon'], $arr)==true){
								array_push ($arr[$ktdate['year'].'-'.$ktdate['mon']],$ob);
							}else{
								$arr[$ktdate['year'].'-'.$ktdate['mon']]=array();
								$arr[$ktdate['year'].'-'.$ktdate['mon']][]=$ob;
							}
						}
					}
				}else{
					if($rin[$time]=='0000-00-00' || $rin[$time]=='')
						$ktdate=0;
					else
						$ktdate=getdate(strtotime($rin[$time]));
					
					$ob->Instance($rin['orderid'],$rin['order_time'],$ktdate['mon'],$ktdate['day'],$ktdate['year'],$rin['order_cus'],$rin['order_content'],$rin['order_quantity'],$rin['order_supply_rice'],$rin['order_tax'],$rin['order_total'],$rin['order_time_transaction'],$rin['is_status'],$rin['user_create'],$rin['date_create'],$rin['order_memo'],$rin['status'] );
					$ob->setCusname($rin['order_cusname']);
					if(array_key_exists ($ktdate['year'].'-'.$ktdate['mon'], $arr)==true){
						array_push ($arr[$ktdate['year'].'-'.$ktdate['mon']],$ob);
					}else{
						$arr[$ktdate['year'].'-'.$ktdate['mon']]=array();
						$arr[$ktdate['year'].'-'.$ktdate['mon']][]=$ob;
					}
				}
				
			}
			$_SESSION['manginvoicetax']=$arr;
		}
	}
	if($_REQUEST['loaitimkiem']=='thang' || $_REQUEST['loaitimkiem']=='all'){
		
		
		$sqlinvoice=mysql_query($sql);
		$dem=0;
		
		if(mysql_num_rows($sqlinvoice)>0){
			while($rin=mysql_fetch_array($sqlinvoice)){
				$dem++;
				$ob=new invoicetax();
				if($_REQUEST['not']!='none'){
					if($_REQUEST['not']=='false'){
						if($rin[$time]=='0000-00-00' || $rin[$time]=='')
							$ktdate=0;
						else
							$ktdate=getdate(strtotime($rin[$time]));
						$ob->Instance($rin['orderid'],$rin['order_time'],$ktdate['mon'],$ktdate['day'],$ktdate['year'],$rin['order_cus'],$rin['order_content'],$rin['order_quantity'],$rin['order_supply_rice'],$rin['order_tax'],$rin['order_total'],$rin['order_time_transaction'],$rin['is_status'],$rin['user_create'],$rin['date_create'],$rin['order_memo'],$rin['status'] );
						$ob->setCusname($rin['order_cusname']);
						if(array_key_exists ($ktdate['year'].'-'.$ktdate['mon'], $arr)==true){
							array_push ($arr[$ktdate['year'].'-'.$ktdate['mon']],$ob);
						}else{
							$arr[$ktdate['year'].'-'.$ktdate['mon']]=array();
							$arr[$ktdate['year'].'-'.$ktdate['mon']][]=$ob;
						}
					}
					if($_REQUEST['not']=='true'){
						if($rin['order_time_transaction']=='0000-00-00' || $rin['order_time_transaction']==''){
							if($rin[$time]=='0000-00-00' || $rin[$time]=='')
								$ktdate=0;
							else
								$ktdate=getdate(strtotime($rin[$time]));
							$ob->Instance($rin['orderid'],$rin['order_time'],$ktdate['mon'],$ktdate['day'],$ktdate['year'],$rin['order_cus'],$rin['order_content'],$rin['order_quantity'],$rin['order_supply_rice'],$rin['order_tax'],$rin['order_total'],$rin['order_time_transaction'],$rin['is_status'],$rin['user_create'],$rin['date_create'],$rin['order_memo'],$rin['status'] );
							$ob->setCusname($rin['order_cusname']);
							if(array_key_exists ($ktdate['year'].'-'.$ktdate['mon'], $arr)==true){
								array_push ($arr[$ktdate['year'].'-'.$ktdate['mon']],$ob);
							}else{
								$arr[$ktdate['year'].'-'.$ktdate['mon']]=array();
								$arr[$ktdate['year'].'-'.$ktdate['mon']][]=$ob;
							}
						}
					}
				}else{
					if($rin[$time]=='0000-00-00' || $rin[$time]=='')
						$ktdate=0;
					else
						$ktdate=getdate(strtotime($rin[$time]));
					$ob->Instance($rin['orderid'],$rin['order_time'],$ktdate['mon'],$ktdate['day'],$ktdate['year'],$rin['order_cus'],$rin['order_content'],$rin['order_quantity'],$rin['order_supply_rice'],$rin['order_tax'],$rin['order_total'],$rin['order_time_transaction'],$rin['is_status'],$rin['user_create'],$rin['date_create'],$rin['order_memo'],$rin['status'] );
					$ob->setCusname($rin['order_cusname']);
					if(array_key_exists ($ktdate['year'].'-'.$ktdate['mon'], $arr)==true){
						array_push ($arr[$ktdate['year'].'-'.$ktdate['mon']],$ob);
					}else{
						$arr[$ktdate['year'].'-'.$ktdate['mon']]=array();
						$arr[$ktdate['year'].'-'.$ktdate['mon']][]=$ob;
					}
				}
			}
			$_SESSION['manginvoicetax']=$arr;
		}
	}
}
$addressbrowser = $_SERVER['SERVER_NAME'];
$temp = explode(".", $addressbrowser);
$queryDepartment = mysql_query("SELECT d.IDDepartment,dl.DepartmentName FROM department d,department_lang dl WHERE d.IDDepartment=dl.IDDepartment AND dl.LangID='$lang';");
$querySendMail = mysql_query("SELECT e.IDEmployee,e.FullName FROM list_sendmail l,employee e WHERE l.employee_id=".$_SESSION['IDEmployee']." AND e.IDEmployee=l.employee_id_sendmail GROUP BY l.employee_id_sendmail");
include '../../popup/popup_reference1.php';
?>
			
				           
				          <div>
			        	<table width="100%" border="0" class="ftable" >
				            <tr>
				            	<th style="width: 2%;min-width: 40px"><a onclick="delorder('<?=$_REQUEST['loaitimkiem']?>',<?=$status?>,'<?=$typedate?>','<?=$_REQUEST['not']?>',<?=$dem?>)"><img src="images/del.png" /></a></th>
				                <th style="width: 2%;min-width: 40px" ><label><input type="checkbox" checked="checked" id="check_no"><?=$l_no?></label></th>
				                <th style="width: 10%;min-width: 100px"><label><input type="checkbox" checked="checked" id="check_ngaythangnam"><?=$l_ngaythangnam?></label></th>
				                <th style="width: 18%;min-width: 170px"><label><input type="checkbox" checked="checked" id="check_company_name"><?=$l_company_name?></label></th>
				                <th style="width: 35%;min-width: 220px"><label><input type="checkbox" checked="checked" id="check_product_item"><?=$l_product_item?></label></th>
				                <th style="display: none;"><label><input type="checkbox" id="check_quantity"><?=$l_quantity?></label></th>
				                <th style="width: 8%;min-width: 80px"><label><input type="checkbox" checked="checked" id="check_Supply_price"><?=$l_Supply_price?></label></th>
				                <th style="width: 8%;min-width: 80px"><label> <input type="checkbox" checked="checked" id="check_vat"><?=$l_vat?></label></th>
				                <th style="width: 8%;min-width: 80px"><label><input type="checkbox" checked="checked" id="check_amount"><?=$l_amount?></label></th>
				                <th style="width: 10%;min-width: 100px"><label><input type="checkbox" id="check_thoigiangiaodich"><?=$l_thoigiangiaodich?></label></th>
				                <th style="width: 10%;min-width: 120px"><label><input type="checkbox" id="check_memo"><?=$l_memo?></label></th>
				                <th style="width: 8%;min-width: 80px"></th>
				            </tr>
				           
				           <?php 
				           $soluong=count($arr);
				           if($soluong>0){
				           		$vitri=0;
				           		foreach($arr as $thoigian=>$mgiatri){
				           			$tonggiacungcap=0;
				           			$tongthue=0;
				           			$tongtien=0;
				           			$dem=count($mgiatri);
				           			$d=0;
				           			if($dem>0){
				           				for($i=0;$i<$dem;$i++){
				           					$inobject= unserialize (serialize ($mgiatri[$i]));
				           					
				           ?>
								            <tr>
								            	<td><input type="checkbox" id="check<?=$vitri?>" name="check<?=$vitri?>" value="<?=$inobject->orderid?>" /></td>
								                <td style="padding: 5px;"><?=($vitri+1)?></td>
								                <td><?=$inobject->ordertime?></td>
								                <td style="text-align:left"><?=$inobject->cusname?></td>
								                <td style="text-align:left"><?=$inobject->order_content?></td>
								                <td style="display: none;"><?=number_format($inobject->order_quantity)?></td>
								                <td style="text-align:right;"><?=number_format($inobject->order_suplly_rice)?></td>
								                <td style="text-align:right;"><?=number_format($inobject->order_tax)?></td>
								                <td style="text-align:right;"><?=number_format($inobject->order_total)?></td>
								                <td><?php 
								                if($inobject->nstatus==1)
								                	echo "-";
								                else echo $inobject->order_time_transaction;
								                ?></td>
								                <td><?=$inobject->order_memo?></td>
								                <td><img src="images/email.png"  onclick="setdata('<?=$inobject->orderid?>','<?=$lang?>','<?=$temp[0]?>')" title="<?=$l_sendmail?>" /></td>
								            </tr>
						            <?php 
						            		if($inobject->order_time_transaction!=""){
						            			$d++;
						            		}
						            		$tonggiacungcap +=$inobject->order_suplly_rice;
						            		$tongthue +=$inobject->order_tax;
						            		$tongtien +=$inobject->order_total;
						            		$vitri++;
				           				}
				           			}
				           			?>
						            <tr class="coltr2" style="font-weight:bold;font-size:14px;">
						                <td colspan="5"  style="padding: 10px;">
											<?php 
												if($_REQUEST['loaitimkiem']=="thang"){
													?>
													<?php echo $l_month;?> : <font color="red"><?php echo $thoigian; ?></font>  -  <?php echo $type;?> : <font color="blue"><?php echo number_format($d);?></font> 
													<?php 
												}else if($_REQUEST['loaitimkiem']=="qui"){
													?>
													<?php echo $l_quy;?> : <?php ?>  -  <?php echo $l_co;?>  <?php echo number_format($d);?> <?php echo $type;?>
													<?php 
												}else if($_REQUEST['loaitimkiem']=="all"){
													?>
													<?php echo $l_month;?> : <font color="red"><?php echo $thoigian; ?></font>  -  <?php echo $type;?> : <font color="blue"><?php echo number_format($d);?></font> 
													<?php 
												}else{
													?>
													<?php echo $l_days;?> : <font color="red"><?php echo $thoigian; ?></font>  -  <?php echo $type;?> : <font color="blue"><?php echo number_format($d);?></font> 
													<?php 
												}
											?>
										</td>
						                <td style="display: none;"></td>
						                <td style="text-align:right;"><?php echo number_format($tonggiacungcap);?></td>
						                <td style="text-align:right;"><?php echo number_format($tongthue);?></td>
						                <td style="text-align:right;"><?php echo number_format($tongtien);?></td>
						                <td></td>
						                <td></td>
						                <td></td>
						            </tr>
				           <?php 
				           			$stonggiacungcap +=$tonggiacungcap;
				           			$stongthue +=$tongthue;
				           			$stongtien +=$tongtien;
				           			
				           		}
				           }else{
				           ?>
				            <tr><td colspan="12" style="height:30px;text-align:left;padding-left:20px;"><?php echo $l_list_emplty;?></td></tr>
				           <?php 
				           }
				           ?>
				            
				            <tr style="font-weight:bold;font-size:15px;color:green;">
				                <td colspan="5" style="padding: 10px;"><?php echo $l_tongdon?></td>
				                <td style="display: none;"></td>
				                <td style="text-align:right;"><?php echo number_format($stonggiacungcap);?></td>
				                <td style="text-align:right;"><?php echo number_format($stongthue);?></td>
				                <td style="text-align:right;"><?php echo number_format($stongtien);?></td>
				                <td style="text-align:right;"></td>
				                <td></td>
				                <td></td>
				            </tr>
				        </table>
			        </div>
				   
<?php mysql_close($connection);?>